<template>
    <a-modal
        title="组织选择"
        :visible="visible"
        @ok="handleOk"
        @cancel="visible = false"
        class="normal-modal"
    >
        <searchData :searchData="searchArr" @search="search"></searchData>
        <b-table
            ref="table"
            :selectConfig="{ use: true, type: 'radio', rowKey: 'id'  }"
            :pageKeys=" ['pageNum', 'pageSize', 'total']"
            :columns="columns"
            @row-click="(e,row) => this.selectRow = row"
            :request="loadData">
            <span slot="num" slot-scope="text, record, index">{{ index + 1 }}</span>
        </b-table>
    </a-modal>
</template>
<script>
import { orgsPname, pubOrgList } from '@/api/material/public/public'

export default {
    name: 'detail-dialog',
    props: {
        otherData: {
            type: Object,
            default() {
                return null
            }
        },
        orgCode: {
            type: String,
            default() {
                return ''
            }
        }
    },
    data: function() {
        return {
            visible: false,
            columns: [
                {
                    title: '序号',
                    scopedSlots: { customRender: 'num' }
                },
                {
                    title: '组织名称',
                    dataIndex: 'name'
                },
                // {
                //     title: '组织编码',
                //     dataIndex: 'code'
                // },
                {
                    title: '上级组织名称',
                    dataIndex: 'pName'
                }
                // {
                //     title: '上级组织编码',
                //     dataIndex: 'parentCode'
                // }
            ],
            searchArr: [
                {
                    name: '组织名称',
                    value: 'nameLike',
                    type: 'input',
                     span: 8
                },
                {
                    name: '组织编码',
                    value: 'codeLike',
                    type: 'input',
                     span: 8
                }
            ],
            queryParams: {},
            selectRow: null,
            loadData: params => {
                let searchData = Object.assign(params, this.queryParams)
                if (this.orgCode) {
                    searchData.containTags = [this.orgCode]
                }
                if (this.otherData) {
                    searchData = Object.assign(this.otherData, params, this.queryParams)
                }
                return orgsPname(searchData).then(res => {
                    if (res.status === 200) {
                        return { code: 200, data: res.data.list, ...res.data }
                    }
                })
            }
        }
    },
    methods: {
        open() {
            this.visible = true
            this.search()
        },
        handleOk() {
            this.visible = false
            this.$emit('getOrg', this.selectRow)
        },
        search(val) {
            this.queryParams = val || {}
            this.$refs.table && this.$refs.table.getData(null, true)
        }
    }
}
</script>
